home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_casm / snip9611.zip / PRTOGGLE.C < prev    next >
C/C++ Source or Header  |  1996-11-24  |  2KB  |  70 lines

  1. /* +++Date last modified: 02-Sep-1996 */
  2.  
  3. /*
  4. **  prtoggle()
  5. **
  6. **  Tee's all standard output to the printer.
  7. **
  8. **  Parameters: None
  9. **
  10. **  Returns:  0 if operation was successful.
  11. **           -1 if stdout or stdin is redirected.
  12. **
  13. **  Side effects: Flushes the keyboard buffer
  14. **
  15. **  Original Copyright 1988-1991 by Bob Stout as part of
  16. **  the MicroFirm Function Library (MFL)
  17. **
  18. **  The user is granted a free limited license to use this source file
  19. **  to create royalty-free programs, subject to the terms of the
  20. **  license restrictions specified in the LICENSE.MFL file.
  21. */
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <conio.h>
  26. #include <io.h>
  27. #include "sniptype.h"
  28. #include "sniprint.h"
  29. #include "pchwio.h"
  30.  
  31. static unsigned head, tail;
  32. static int idx = 0;
  33. static unsigned keystack[16][2];
  34.  
  35. int ungetkey(unsigned key)
  36. {
  37.         int count;
  38.  
  39.         head = peekw(0x40, 0x1a);
  40.         tail = peekw(0x40, 0x1c);
  41.         count = tail - head;
  42.         if (0 > count)
  43.                 count += (16 * sizeof(unsigned));
  44.         count >>= 1;
  45.  
  46.         if (15 > count)
  47.         {
  48.                 keystack[idx][0] = peek(0x40, tail);
  49.                 keystack[idx][1] = tail;
  50.                 pokew(0x40, tail, key);
  51.                 tail += sizeof(unsigned);
  52.                 if (0x3e <= tail)
  53.                         tail = 0x1e;
  54.                 pokew(0x40, 0x1c, tail);
  55.                 return key;
  56.         }
  57.         return EOF;
  58. }
  59.  
  60. int prtoggle(void)
  61. {
  62.       if (!isatty(fileno(stdin)) || !isatty(fileno(stdout)))
  63.             return -1;
  64.       while (kbhit())           /* Flush the keyboard buffer            */
  65.             getch();
  66.       ungetkey('P' - 64);       /* Stuff a Ctrl-P into the buffer       */
  67.       system("");               /* Let COMMAND.COM do the work          */
  68.       return 0;
  69. }
  70.